package com.uphone.kingmall.activity.order;

import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.china.zhuoyue.R;
import com.lzy.okgo.model.HttpParams;
import com.uphone.kingmall.activity.GoodsDetailActivity;
import com.uphone.kingmall.adapter.RvRecommendGoodsAdapter;
import com.uphone.kingmall.base.BaseActivity;
import com.uphone.kingmall.bean.GoodsListBean;
import com.uphone.kingmall.listener.NetListCallBack;
import com.uphone.kingmall.utils.CommonUtil;
import com.uphone.kingmall.utils.ConstansUtils;
import com.uphone.kingmall.utils.MyUrl;
import com.uphone.kingmall.utils.intent.IntentData;
import com.uphone.kingmall.utils.intent.IntentUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * <pre>
 *     author : 孙增艳
 *     e-mail : sunzengyan@outlook.com
 *     time   : 2019/2/28
 *     desc   : 评价成功页面
 *     version: 1.0
 * </pre>
 */
public class EvaluateSuccessActivity extends BaseActivity {
    @BindView(R.id.rv_goods)
    RecyclerView rvGoods;
    @IntentData
    int id = -1;

    private List<GoodsListBean.DataBean> recommendGoodsBeans = new ArrayList<>();
    private RvRecommendGoodsAdapter recommendGoodsAdapter;

    @Override
    public int getLayoutContentId() {
        return R.layout.kingmall_activity_evaluate_success;
    }

    @Override
    public void initView() {
        setStatusBar();
        recommendGoodsAdapter = new RvRecommendGoodsAdapter(this, recommendGoodsBeans);
        rvGoods.setLayoutManager(new GridLayoutManager(this, 2));
        rvGoods.setAdapter(recommendGoodsAdapter);

        recommendGoodsAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                IntentUtils.getInstance()
                        .with(EvaluateSuccessActivity.this, GoodsDetailActivity.class)
                        .putInt(ConstansUtils.ID, recommendGoodsBeans.get(position).getGoodsId())
                        .start();
            }
        });
    }

    @Override
    public void initData() {
        HttpParams params = new HttpParams();
        params.put("orderId", id);
        params.put("page", 1);
        params.put("limit", 50);
        CommonUtil.netRv(new GoodsListBean(), recommendGoodsAdapter, recommendGoodsBeans, MyUrl.getOrderRecoGoods, params, 1, new NetListCallBack<GoodsListBean.DataBean>() {
            @Override
            public void callBack(List<GoodsListBean.DataBean> list) {
                recommendGoodsBeans = list;
            }
        });

    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }
}
